<template>
  

  <div style="padding-left:25%;padding-right:25%">
    <van-field v-model='name' placeholder='快递名称' class="info"></van-field>
    <van-field v-model='to_place' placeholder='目的地' class="info"></van-field>
    <van-field v-model='from_place' placeholder='寄件地址' class="info"></van-field>
    <van-field v-model='sender' placeholder='寄件人' class="info"></van-field>
    <van-field v-model='receiver' placeholder='收件人' class="info"></van-field>
    <van-field v-model='description' placeholder='快递信息' class="info"></van-field>
    <van-field v-model='receiver_phone' placeholder='收件人电话' class="info"></van-field>
    <van-field v-model='sender_phone' placeholder='寄件人电话' class="info"></van-field>
    <van-button @click='submit()' id="submit">提交</van-button>
  </div>

</template>



<script>
import { add_fast_mail } from "@/components/axios_api/api.js"; // @符号指的是src路径
export default {
  data() {
    return {
      name: "",
      to_place: "",
      from_place: "",
      sender: '',
      receiver: '',
      description: '',
      receiver_phone: '',
      sender_phone: '',
    };
  },
  
  methods: {

        // 获取表单数据
        get_data () {
            let data = {
                name: this.name,
                to_place: this.to_place,
                from_place: this.from_place,
                sender: this.sender,
                receiver: this.receiver,
                description: this.description,
                receiver_phone: this.receiver_phone,
                sender_phone: this.sender_phone,
            }
            return data
        },

        // 清空表中数据
        clear_mail_data () {
        this.name = ''
        this.to_place = ''
        this.from_place = ''
        this.sender = ''
        this.receiver = ''
        this.description = ''
        this.receiver_phone = ''
        this.sender_phone = ''
        },

        // 提交表单
        submit() {
            let data = this.get_data()
            add_fast_mail(data).then((res) => {
                if (res.code == 200) {
                    alert('成功')
                } else {
                    alert("失败");
                }
        });
        }
  },
  mounted() {
  },
};
</script>

<style>
    .info{
        margin-top: 10px;
    }
    #submit{
        margin-top: 20px;
    }
</style>